package com.sofwin.base;

import lombok.Data;

import java.io.Serializable;

/**
 * @packageName: com.sofwin.base
 * @author: andyliu
 * @date: 2022/8/5 11:03
 * @email 115176513@qq.com
 * @description: 异步请求的响应结果
 */
@Data
public class ResponseEntity implements Serializable {
    private static final long serialVersionUID = -6520098461998726218L;
    // 自定义响应状态码 200 500
    private Integer code;
    // 响应信息 操作成功、操作失败
    private String msg;
    // 响应的数据
    private Object result;

    public ResponseEntity(Integer code, String msg, Object result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public ResponseEntity() {
    }

    /**
     * 静态方法 操作成功
     * @param msg
     * @param result
     * @return
     */
    public static ResponseEntity success(String msg, Object result){
        return new ResponseEntity(200,msg,result);
    }
    public static ResponseEntity success(Object result){
        return new ResponseEntity(200,"操作成功",result);
    }
    public static ResponseEntity success(){
        return new ResponseEntity(200,"操作成功",null);
    }

    public static ResponseEntity error(Integer code, String msg, Object result){
        return new ResponseEntity(code,msg,result);
    }
    public static ResponseEntity error(String msg, Object result){
        return new ResponseEntity(500,msg,result);
    }
    public static ResponseEntity error(Object result){
        return new ResponseEntity(500,"操作失败",result);
    }
    public static ResponseEntity error(){
        return new ResponseEntity(500,"操作失败",null);
    }

}
